package com.buybuyyi.stylistcrm.resource.goods.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.buybuyyi.stylistcrm.object.util.BeanTranslater;
import com.buybuyyi.stylistcrm.resource.goods.dao.DicBrandDao;
import com.buybuyyi.stylistcrm.resource.goods.dao.DicClassificationsDao;
import com.buybuyyi.stylistcrm.resource.goods.dao.DicMaterialBrandDao;
import com.buybuyyi.stylistcrm.resource.goods.dao.DicMaterialCottonDao;
import com.buybuyyi.stylistcrm.resource.goods.dao.DicTagsDao;
import com.buybuyyi.stylistcrm.resource.goods.po.DicBrand;
import com.buybuyyi.stylistcrm.resource.goods.po.DicClassification;
import com.buybuyyi.stylistcrm.resource.goods.po.DicMaterialBrand;
import com.buybuyyi.stylistcrm.resource.goods.po.DicMaterialCotton;
import com.buybuyyi.stylistcrm.resource.goods.po.DicTags;

import stylistcrm.core.services.goods.dto.DicBrandDTO;
import stylistcrm.core.services.goods.dto.DicClassificationsDTO;
import stylistcrm.core.services.goods.dto.DicMaterialBrandDTO;
import stylistcrm.core.services.goods.dto.DicMaterialCottonDTO;
import stylistcrm.core.services.goods.dto.DicTagsDTO;
import stylistcrm.core.services.goods.dto.GoodsResultDTO;
import stylistcrm.core.services.goods.service.IDictionaryService;

@Service
public class DictionaryService implements IDictionaryService{

	@Autowired
	DicBrandDao dicBrandDao;

	@Autowired
	DicClassificationsDao dicClassificationsDao;

	@Autowired
	DicMaterialBrandDao dicMaterialBrandDao;

	@Autowired
	DicMaterialCottonDao dicMaterialCottonDao;

	@Autowired
	DicTagsDao dicTagsDao;

	@Override
	public List<DicBrandDTO> getDicBrandList() throws Exception {
		List<DicBrand> dicBrands=dicBrandDao.getAllDicBrand();

		List<DicBrandDTO> dicBrandDtos=new ArrayList<DicBrandDTO>();

		if(null != dicBrands && dicBrands.size()>0){
			for(DicBrand dicBrand : dicBrands){
				DicBrandDTO  dicBrandDTO=new DicBrandDTO();
				BeanTranslater.copyProperties(dicBrand, dicBrandDTO);
				dicBrandDtos.add(dicBrandDTO);
			}

		}
		return dicBrandDtos;
	}

	@Override
	public GoodsResultDTO saveDicBrand(DicBrandDTO brandDto) throws Exception {
		GoodsResultDTO resultDto=new GoodsResultDTO();


		DicBrand dicBrand=new DicBrand();
		if(null != brandDto){
			BeanTranslater.copyProperties(brandDto, dicBrand);
			dicBrandDao.insert(dicBrand);
			resultDto.setCode("1");
			resultDto.setMessage("保存成功");
		}
		return resultDto;
	}

	@Override
	public List<DicClassificationsDTO> getDicClassicication() throws Exception {
		List<DicClassification> dicClassifications=dicClassificationsDao.getAllDicClassifications();
		List<DicClassificationsDTO> dicClassificationsDTOs=new ArrayList<DicClassificationsDTO>();

		if(null != dicClassifications && dicClassifications.size()>0){
			for(DicClassification dicClassification : dicClassifications){
				DicClassificationsDTO dicClassificationsDTO=new DicClassificationsDTO();
				BeanTranslater.copyProperties(dicClassification, dicClassificationsDTO);
				dicClassificationsDTOs.add(dicClassificationsDTO);
			}
		}
		return dicClassificationsDTOs;

	}

	@Override
	public GoodsResultDTO saveDicClassicication(DicClassificationsDTO dicClassFication) throws Exception {
		GoodsResultDTO resultDto=new GoodsResultDTO();
		DicClassification dicClassification=new DicClassification();
		if(null != dicClassFication){
			BeanTranslater.copyProperties(dicClassFication, dicClassification);
			dicClassificationsDao.insert(dicClassification);
			resultDto.setCode("1");
			resultDto.setMessage("保存成功");
		}
		return resultDto;
	}

	@Override
	public List<DicMaterialBrandDTO> getDicMaterialBrandList() throws Exception {
		List<DicMaterialBrand> dicMaterialBrands=dicMaterialBrandDao.getAllDicMaterialBrand();

		List<DicMaterialBrandDTO> dicMaterialBrandsDtos=new ArrayList<DicMaterialBrandDTO>();
		if(null != dicMaterialBrands && dicMaterialBrands.size()>0){
			for(DicMaterialBrand dicMaterialBrand : dicMaterialBrands){
				DicMaterialBrandDTO dicMaterialBrandDTO=new DicMaterialBrandDTO();
				BeanTranslater.copyProperties(dicMaterialBrand, dicMaterialBrandDTO);
				dicMaterialBrandsDtos.add(dicMaterialBrandDTO);
			}

		}
		return dicMaterialBrandsDtos;
	}

	@Override
	public GoodsResultDTO saveDicMaterialBrand(DicMaterialBrandDTO dicMaterialbrandDto) throws Exception {
		GoodsResultDTO resultDto=new GoodsResultDTO();
		DicMaterialBrand dicMaterialBrand=new DicMaterialBrand();
		if(null != dicMaterialbrandDto){
			BeanTranslater.copyProperties(dicMaterialbrandDto, dicMaterialBrand);
			dicMaterialBrandDao.insert(dicMaterialBrand);
			resultDto.setCode("1");
			resultDto.setMessage("保存成功");
		}
		return resultDto;
	}

	@Override
	public List<DicMaterialCottonDTO> getDicMaterialCottonList() throws Exception {
		List<DicMaterialCotton> dicMaterialCottons=dicMaterialCottonDao.getAllDicMaterialCotton();

		List<DicMaterialCottonDTO> dicMaterialCottonDtos=new ArrayList<DicMaterialCottonDTO>();
		if(null != dicMaterialCottons && dicMaterialCottons.size()>0){
			for(DicMaterialCotton dicMaterialCotton1 :dicMaterialCottons ){
				DicMaterialCottonDTO dicMaterialCottonDTO=new DicMaterialCottonDTO();
				BeanTranslater.copyProperties(dicMaterialCotton1, dicMaterialCottonDTO);
				dicMaterialCottonDtos.add(dicMaterialCottonDTO);
			}
		}
		return dicMaterialCottonDtos;
	}

	@Override
	public GoodsResultDTO saveMaterialCottonDTO(DicMaterialCottonDTO dicMaterialCottonDto) throws Exception {
		GoodsResultDTO resultDto=new GoodsResultDTO();
		DicMaterialCotton dicMaterialCotton=new DicMaterialCotton();
		if(null != dicMaterialCottonDto){
			BeanTranslater.copyProperties(dicMaterialCottonDto, dicMaterialCotton);
			dicMaterialCottonDao.insert(dicMaterialCotton);
			resultDto.setCode("1");
			resultDto.setMessage("保存成功");
		}
		return resultDto;
	}

	@Override
	public List<DicTagsDTO> getDicTagsList() throws Exception {
		List<DicTags>  dicTags=dicTagsDao.getAllDicTags();
		List<DicTagsDTO> dicTagsDTODtos=new ArrayList<DicTagsDTO>();
		if(null != dicTags && dicTags.size()>0){
			for(DicTags dicTags1 : dicTags){
				DicTagsDTO dicTagsDTO=new DicTagsDTO();
				BeanTranslater.copyProperties(dicTags1, dicTagsDTO);
				dicTagsDTODtos.add(dicTagsDTO);
			}

		}
		return dicTagsDTODtos;
	}

	@Override
	public GoodsResultDTO saveDicTags(DicTagsDTO brandDto) throws Exception {
		GoodsResultDTO resultDto=new GoodsResultDTO();
		DicTags dicTags=new DicTags();
		if(null != brandDto){
			BeanTranslater.copyProperties(brandDto, dicTags);
			dicTagsDao.insert(dicTags);
			resultDto.setCode("1");
			resultDto.setMessage("保存成功");
		}
		return resultDto;
	}

}
